﻿//*********************************************************************************************************
//*************************************** DUNG CHUNG ******************************************************
//*********************************************************************************************************

        /*
        *   CHON HET
        */
        function make_checkall()
        {
            var nodeList = window.document.getElementsByName("checkedIDList[]");
            for (i = 0; i < nodeList.length; i++)
            {
                nodeList[i].checked=true
            }
        }

        /*
        *   BO CHON HET
        */
        function make_uncheckall()
        {
            var nodeList = window.document.getElementsByName("checkedIDList[]");
            for (i = 0; i < nodeList.length; i++)
            {
                nodeList[i].checked=false
            }
        }
        
        /*
        *   XU LY KHI CLICK CHON
        */
        function process_check_management(id){
            if(window.document.getElementById(id).checked == true){
                make_checkall();
            }else{
                make_uncheckall();
            }
        }
        
        function check_search_month(id){
            if(window.document.getElementById(id).checked == true){
                show_select_month();
            }else{
                unshow_select_month();
            }        
        }

        function check_search_day(id){
            if(window.document.getElementById(id).checked == true){
                show_select_day();
            }else{
                unshow_select_day();
            }        
        }

        /*
        *   THE HIEN THANG
        */
        function show_select_month(){
            var res = "tháng <select id='value_search_month_from'>";
            for(i=1; i<=12; i++){
                res = res + "<option value='"+i+"'>"+i+"</option>";
            }
            res = res + "</select>&nbsp;&nbsp;";
            $("#span_show_month_from").html(res);
            
            res = "tháng <select id='value_search_month_to'>";
            for(i=1; i<=12; i++){
                res = res + "<option value='"+i+"'>"+i+"</option>";
            }
            res = res + "</select>&nbsp;&nbsp;";
            
            $("#span_show_month_to").html(res);
            
            res = "<input id='search_day' type='checkbox' onclick='check_search_day(this.id)' /> Ngày";
            $("#span_search_day").html(res);
        }
        
        /*
        *   TAT THE HIEN THANG
        */
        function unshow_select_month(){
            $("#span_show_month_from").html("");
            $("#span_show_month_to").html("");
            $("#span_search_day").html("");
            $("#span_show_day_from").html("");
            $("#span_show_day_to").html("");
        }
        
        /*
        *   THE HIEN NGAY
        */
        function show_select_day(){
            var res = "ngày <select id='value_search_day_from'>";
            for(i=1; i<=31; i++){
                res = res + "<option value='"+i+"'>"+i+"</option>";
            }
            res = res + "</select>&nbsp;&nbsp;";
            $("#span_show_day_from").html(res);
            
            res = "ngày <select id='value_search_day_to'>";
            for(i=1; i<=31; i++){
                res = res + "<option value='"+i+"'>"+i+"</option>";
            }
            res = res + "</select>&nbsp;&nbsp;";
            $("#span_show_day_to").html(res);
        }
                
        /*
        *   TAT THE HIEN NGAY
        */
        function unshow_select_day(){
            $("#span_show_day_from").html("");
            $("#span_show_day_to").html("");
        }
        

//       *****************************************************************************************************
//       *                           LOAI SAN PHAM 
//        ****************************************************************************************************

        /*
        *   THE HIEN DANH SACH LOAI SAN PHAM
        *   CO PHAN TRANG
        */        
        function ajax_manage_kinds_of_product(context,totalrow,limit,count){
            if(context == "default"){
                page = '1';
            }
            var iTotalrow = parseInt(totalrow);
            var iLimit = parseInt(limit);
            if(context == "next"){
                page = parseInt($("#pageIndex").html());
                if(((page+1)*iLimit)<(iTotalrow+iLimit)){
                    page = page + 1;
                }else{
                    return;
                }
            }
            if(context == "previous"){
                page = parseInt($("#pageIndex").html());
                if(page>1){
                    page = page - 1;
                }else{
                    return;
                }
            }
            if(context == "update"){
                page = parseInt($("#pageIndex").html());
                var iCount = parseInt(count);
                if((page*iLimit) >= (iTotalrow+iLimit-iCount)){
                    page --;
                }
            }
            
            if(context == "jump"){
                page = count;
            }
                
            var data = {
                task: 'manage_kinds_of_product',
                page: page
            }
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");        
        }
        
        /*
        *   XOA 1 LOAI SAN PHAM
        */
        function ajax_delete_kinds_of_product(id,totalrow,limit,search){
            var choose = confirm('Bạn có muốn xóa loại sản phẩm này?');
            if(choose == true){
                var data = {
                    task: 'delete_kinds_of_product',
                    id: id
                }
                $.get("controller.aspx",data, function(){
                    alert("Xóa thành công");
                    if(search == 'false'){
                        ajax_manage_kinds_of_product("update",totalrow,limit,1);
                    }else{
                        ajax_search_kinds_of_product("update",totalrow,limit,1);
                    }
                }, "text");
            }        
        }
        
        /*
        *   XOA NHIEU LOAI SAN PHAM KHI DUOC CHON
        */
        function ajax_delete_checked_kinds_of_product(totalrow,limit,search){
            var checkedIDList = document.getElementsByName("checkedIDList[]");
            var strCheckedIDList = "";
            var flag = false;
            var count = 0;
            for (i = 0; i < checkedIDList.length; i++){
                if(flag == false){
                    if(checkedIDList[i].checked == true){
                        strCheckedIDList = strCheckedIDList + checkedIDList[i].value;
                        flag = true;
                        count ++;
                    }
                }else{
                    if(checkedIDList[i].checked == true){
                        strCheckedIDList = strCheckedIDList + "," + checkedIDList[i].value;
                        count ++;
                    }
                }
            }

            if(strCheckedIDList == ""){
                return;
            }
            var choose = confirm('Bạn có muốn xóa các loại sản phẩm đã chọn?');
            if(choose == true){
                var data = {
                    task: 'delete_checked_kinds_of_product',
                    checkedIDList: strCheckedIDList
                }
                $.get("controller.aspx",data, function(){
                    alert("Xóa thành công");
                    if(search == 'false'){
                        ajax_manage_kinds_of_product("update",totalrow,limit,count);
                    }else{
                        ajax_search_kinds_of_product("update",totalrow,limit,count);
                    }
                }, "text");
            }        
        }
        
        /*
        *   THE HIEN FORM CAP NHAT 1 LOAI SAN PHAM
        */
        function ajax_update_kinds_of_product_getform(id){
            if($("#key_search").val() == ""){
                var data = {
                    task: 'update_kinds_of_product',
                    id: id,
                    get_form: 'true'
                }
            }else{
                var data = {
                    task: 'update_kinds_of_product',
                    id: id,
                    key_search: $("#key_search").val(),
                    get_form: 'true'
                }
            }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }
        
        /*
        *   XU LY CAP NHAT 1 LOAI SAN PHAM
        */
        function ajax_update_kinds_of_product_process(){
            if($('#name').val() == ""){
                alert("Xin vui lòng nhập đầy đủ các thông tin yêu cầu.");
                return;
            }
        
            var data = {
                task: 'update_kinds_of_product',
                id: $('#kinds_of_product_id').val(),
                name: $('#name').val(),
                send_info: 'true'
            }
            
            $.get("controller.aspx",data, function(res){
                alert("Cập nhật thành công");
                ajax_manage_kinds_of_product('default','-1','10','-1')
            }, "text");
        }        

        /*
        *   TIM KIEM LOAI SAN PHAM
        */
        function ajax_search_kinds_of_product(context,totalrow,limit,count){
            if(context == "default"){
                page = '1';
            }
            var iTotalrow = parseInt(totalrow);
            var iLimit = parseInt(limit);
            if(context == "next"){
                page = parseInt($("#pageIndex").html());
                if(((page+1)*iLimit)<(iTotalrow+iLimit)){
                    page = page + 1;
                }else{
                    return;
                }
            }
            if(context == "previous"){
                page = parseInt($("#pageIndex").html());
                if(page>1){
                    page = page - 1;
                }else{
                    return;
                }
            }
            if(context == "update"){
                page = parseInt($("#pageIndex").html());
                var iCount = parseInt(count);
                if((page*iLimit) >= (iTotalrow+iLimit-iCount)){
                    page --;
                }
            }
            
            if(context == "jump")
            {
                page = count;
            }
            
            if(context != "default" && context != "previous" && 
                context != "update" && context != "next" && context != "jump"){
                var data = {
                    task: 'search_kinds_of_product',
                    key_search: context,
                    page: page
                }
            }else{
                var data = {
                    task: 'search_kinds_of_product',
                    key_search: $("#key_search").val(),
                    page: page
                }
            }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }

        /*
        *   THE HIEN FORM THEM 1 LOAI SAN PHAM
        */
        function ajax_add_new_kinds_of_product_getform(){
                var data = {
                    task: 'add_new_kinds_of_product',
                    get_form: 'true'
                }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }

        /*
        *   XU LY THEM 1 LOAI SAN PHAM
        */
        function ajax_add_new_kinds_of_product_process(){
            if($('#name').val() == ""){
                alert("Xin vui lòng nhập đầy đủ các thông tin yêu cầu.");
                return;
            }
                var data = {
                    task: 'add_new_kinds_of_product',
                    name: $('#name').val(),
                    send_info: 'true'
                }
            
            $.get("controller.aspx",data, function(res){
                alert("Thêm loại sản phẩm mới thành công thành công");
                ajax_manage_kinds_of_product('default','-1','10','-1')
            }, "text");
        }

//       /*********************************************************************************************
//                         NHA SAN XUAT 
//        *********************************************************************************************
//        
        /*
        *   THE HIEN DANH SACH NHA SAN XUAT
        *   CO PHAN TRANG
        */        
        function ajax_manage_manufacturer(context,totalrow,limit,count){
            if(context == "default"){
                page = '1';
            }
            var iTotalrow = parseInt(totalrow);
            var iLimit = parseInt(limit);
            if(context == "next"){
                page = parseInt($("#pageIndex").html());
                if(((page+1)*iLimit)<(iTotalrow+iLimit)){
                    page = page + 1;
                }else{
                    return;
                }
            }
            if(context == "previous"){
                page = parseInt($("#pageIndex").html());
                if(page>1){
                    page = page - 1;
                }else{
                    return;
                }
            }
            if(context == "update"){
                page = parseInt($("#pageIndex").html());
                var iCount = parseInt(count);
                if((page*iLimit) >= (iTotalrow+iLimit-iCount)){
                    page --;
                }
            }
            
            if(context == "jump"){
                page = count;
            }
                
            var data = {
                task: 'manage_manufacturer',
                page: page
            }
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");        
        }
        
        /*
        *   XOA 1 NHA SAN XUAT
        */
        function ajax_delete_manufacturer(id,totalrow,limit,search){
            var choose = confirm('Bạn có muốn xóa nhà sản xuất này?');
            if(choose == true){
                var data = {
                    task: 'delete_manufacturer',
                    id: id
                }
                $.get("controller.aspx",data, function(){
                    alert("Xóa thành công");
                    if(search == 'false'){
                        ajax_manage_manufacturer("update",totalrow,limit,1);
                    }else{
                        ajax_search_manufacturer("update",totalrow,limit,1);
                    }
                }, "text");
            }        
        }
        
        /*
        *   XOA NHIEU NHA SAN XUAT KHI DUOC CHON
        */
        function ajax_delete_checked_manufacturer(totalrow,limit,search){
            var checkedIDList = document.getElementsByName("checkedIDList[]");
            var strCheckedIDList = "";
            var flag = false;
            var count = 0;
            for (i = 0; i < checkedIDList.length; i++){
                if(flag == false){
                    if(checkedIDList[i].checked == true){
                        strCheckedIDList = strCheckedIDList + checkedIDList[i].value;
                        flag = true;
                        count ++;
                    }
                }else{
                    if(checkedIDList[i].checked == true){
                        strCheckedIDList = strCheckedIDList + "," + checkedIDList[i].value;
                        count ++;
                    }
                }
            }

            if(strCheckedIDList == ""){
                return;
            }
            var choose = confirm('Bạn có muốn xóa các nhà sản xuất đã chọn?');
            if(choose == true){
                var data = {
                    task: 'delete_checked_manufacturer',
                    checkedIDList: strCheckedIDList
                }
                $.get("controller.aspx",data, function(){
                    alert("Xóa thành công");
                    if(search == 'false'){
                        ajax_manage_manufacturer("update",totalrow,limit,count);
                    }else{
                        ajax_search_manufacturer("update",totalrow,limit,count);
                    }
                }, "text");
            }        
        }
        
        /*
        *   THE HIEN FORM CAP NHAT 1 NHA SAN XUAT
        */
        function ajax_update_manufacturer_getform(id){
            if($("#key_search").val() == ""){
                var data = {
                    task: 'update_manufacturer',
                    id: id,
                    get_form: 'true'
                }
            }else{
                var data = {
                    task: 'update_manufacturer',
                    id: id,
                    key_search: $("#key_search").val(),
                    get_form: 'true'
                }
            }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }
        
        /*
        *   XU LY CAP NHAT 1 NHA SAN XUAT
        */
        function ajax_update_manufacturer_process(){
            var data = {
                task: 'update_manufacturer',
                id: $('#manufacturer_id').val(),
                name: $('#name').val(),
                info: $('#info').val(),
                send_info: 'true'
            }
            
            $.get("controller.aspx",data, function(res){
                alert("Cập nhật thành công");
            }, "text");
        }        

        /*
        *   TIM KIEM NHA SAN XUAT
        */
        function ajax_search_manufacturer(context,totalrow,limit,count){
            if(context == "default"){
                page = '1';
            }
            var iTotalrow = parseInt(totalrow);
            var iLimit = parseInt(limit);
            if(context == "next"){
                page = parseInt($("#pageIndex").html());
                if(((page+1)*iLimit)<(iTotalrow+iLimit)){
                    page = page + 1;
                }else{
                    return;
                }
            }
            if(context == "previous"){
                page = parseInt($("#pageIndex").html());
                if(page>1){
                    page = page - 1;
                }else{
                    return;
                }
            }
            if(context == "update"){
                page = parseInt($("#pageIndex").html());
                var iCount = parseInt(count);
                if((page*iLimit) >= (iTotalrow+iLimit-iCount)){
                    page --;
                }
            }
            
            if(context == "jump")
            {
                page = count;
            }
            
            if(context != "default" && context != "previous" && 
                context != "update" && context != "next" && context != "jump"){
                var data = {
                    task: 'search_manufacturer',
                    key_search: context,
                    page: page
                }
            }else{
                var data = {
                    task: 'search_manufacturer',
                    key_search: $("#key_search").val(),
                    page: page
                }
            }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }
        
        /*
        *   THE HIEN FORM THEM 1 NHA SAN XUAT
        */
        function ajax_add_new_manufacturer_getform(){
                var data = {
                    task: 'add_new_manufacturer',
                    get_form: 'true'
                }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }

        /*
        *   XU LY THEM 1 NHA SAN XUAT
        */
        function ajax_add_new_manufacturer_process(){
            if($('#name').val() == "" || $('#info').val() == ""){
                alert("Xin vui lòng nhập đầy đủ các thông tin yêu cầu.");
                return;
            }
                var data = {
                    task: 'add_new_manufacturer',
                    name: $('#name').val(),
                    info: $('#info').val(),
                    send_info: 'true'
                }
            
            $.get("controller.aspx",data, function(res){
                alert("Thêm nhà sản xuất mới thành công thành công");
                ajax_manage_manufacturer('default','-1','10','-1')
            }, "text");
        }
        
//       /*****************************************************************************************************
//                           SAN PHAM 
//        *****************************************************************************************************
        
        /*
        *   THE HIEN DANH SACH SAN PHAM
        *   CO PHAN TRANG
        */        
        function ajax_manage_product(context,totalrow,limit,count){
            if(context == "default"){
                page = '1';
            }
            var iTotalrow = parseInt(totalrow);
            var iLimit = parseInt(limit);
            if(context == "next"){
                page = parseInt($("#pageIndex").html());
                if(((page+1)*iLimit)<(iTotalrow+iLimit)){
                    page = page + 1;
                }else{
                    return;
                }
            }
            if(context == "previous"){
                page = parseInt($("#pageIndex").html());
                if(page>1){
                    page = page - 1;
                }else{
                    return;
                }
            }
            if(context == "update"){
                page = parseInt($("#pageIndex").html());
                var iCount = parseInt(count);
                if((page*iLimit) >= (iTotalrow+iLimit-iCount)){
                    page --;
                }
            }
            
            if(context == "jump"){
                page = count;
            }
                
            var data = {
                task: 'manage_product',
                page: page
            }
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");        
        }
        
        /*
        *   THE HIEN FORM CAP NHAT 1 SAN PHAM
        */
        function ajax_update_product_getform(id){
            if($("#key_search").val() == ""){
                var data = {
                    task: 'update_product',
                    id: id,
                    get_form: 'true'
                }
            }else{
                var data = {
                    task: 'update_product',
                    id: id,
                    key_search: $("#key_search").val(),
                    get_form: 'true'
                }
            }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }
        
        /*
        *   THE HIEN CHI TIET 1 SAN PHAM
        */
        function ajax_view_detail_product(id){
            if($("#key_search").val() == ""){
                var data = {
                    task: 'view_detail_product',
                    id: id,
                }
            }else{
                var data = {
                    task: 'view_detail_product',
                    id: id,
                    key_search: $("#key_search").val(),
                    get_form: 'true'
                }
            }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }
                
        /*
        *   XU LY CAP NHAT 1 SAN PHAM
        */
        function ajax_update_product_process(){
            var data = {
                task: 'update_product',
                id: $('#product_id').val(),
                name: $('#name').val(),
                info: $('#info').val(),
                price: $('#price').val(),
                exist: $('#exist').val(),
                input: $('#input').val(),
                gender: $('#gender').val(),
                kinds_of_product: $('#kinds_of_product').val(),
                manufacturer: $('#manufacturer').val(),
                size: $('#size').val(),
                send_info: 'true'
            }
            
            $.get("controller.aspx",data, function(res){
                alert("Cập nhật thành công");
            }, "text");
        }        

        /*
        *   TIM KIEM SAN PHAM
        */
        function ajax_search_product(context,totalrow,limit,count){
            if(context == "default"){
                page = '1';
            }
            var iTotalrow = parseInt(totalrow);
            var iLimit = parseInt(limit);
            if(context == "next"){
                page = parseInt($("#pageIndex").html());
                if(((page+1)*iLimit)<(iTotalrow+iLimit)){
                    page = page + 1;
                }else{
                    return;
                }
            }
            if(context == "previous"){
                page = parseInt($("#pageIndex").html());
                if(page>1){
                    page = page - 1;
                }else{
                    return;
                }
            }
            if(context == "update"){
                page = parseInt($("#pageIndex").html());
                var iCount = parseInt(count);
                if((page*iLimit) >= (iTotalrow+iLimit-iCount)){
                    page --;
                }
            }
            
            if(context == "jump")
            {
                page = count;
            }
            
            if(context != "default" && context != "previous" && 
                context != "update" && context != "next" && context != "jump"){
                var data = {
                    task: 'search_product',
                    key_search: context,
                    page: page
                }
            }else{
                var data = {
                    task: 'search_product',
                    key_search: $("#key_search").val(),
                    page: page
                }
            }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }
        
        /*
        *   THE HIEN FORM THEM 1 SAN PHAM
        */
        function ajax_add_new_product_getform(){
                var data = {
                    task: 'add_new_product',
                    get_form: 'true'
                }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }

        /*
        *   XU LY THEM 1 SAN PHAM
        */
        function ajax_add_new_product_process(){
            if($('#name').val() == "" || $('#info').val() == "" || 
                $('#price').val() == "" || $('#input').val() == "" || $('#size').val() == ""){
                alert("Xin vui lòng nhập đầy đủ các thông tin yêu cầu.");
                return;
            }
                var data = {
                    task: 'add_new_product',
                    name: $('#name').val(),
                    info: $('#info').val(),
                    price: $('#price').val(),
                    input: $('#input').val(),
                    gender: $('#gender').val(),
                    kinds_of_product: $('#kinds_of_product').val(),
                    manufacturer: $('#manufacturer').val(),
                    size: $('#size').val(),
                    send_info: 'true'
                }
            
            $.get("controller.aspx",data, function(){
                alert("Thêm sản phẩm mới thành công thành công");
                ajax_manage_product('default','-1','10','-1')
            }, "text");
        }
        
//       /**************************************************************************************************
//                           KHACH HANG 
//        **************************************************************************************************
        
        /*
        *   THE HIEN DANH SACH KHACH HANG
        *   CO PHAN TRANG
        */        
        function ajax_manage_customer(context,totalrow,limit,count){
            if(context == "default"){
                page = '1';
            }
            var iTotalrow = parseInt(totalrow);
            var iLimit = parseInt(limit);
            if(context == "next"){
                page = parseInt($("#pageIndex").html());
                if(((page+1)*iLimit)<(iTotalrow+iLimit)){
                    page = page + 1;
                }else{
                    return;
                }
            }
            if(context == "previous"){
                page = parseInt($("#pageIndex").html());
                if(page>1){
                    page = page - 1;
                }else{
                    return;
                }
            }
            if(context == "update"){
                page = parseInt($("#pageIndex").html());
                var iCount = parseInt(count);
                if((page*iLimit) >= (iTotalrow+iLimit-iCount)){
                    page --;
                }
            }
            
            if(context == "jump"){
                page = count;
            }
                
            var data = {
                task: 'manage_customer',
                page: page
            }
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");        
        }
        
        /*
        *   THE HIEN CHI TIET 1 KHACH HANG
        */
        function ajax_view_detail_customer(id){
            if($("#key_search").val() == ""){
                var data = {
                    task: 'view_detail_customer',
                    id: id
                }
            }else{
                var data = {
                    task: 'view_detail_customer',
                    id: id,
                    key_search: $("#key_search").val()
                }
            }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }
        
        /*
        *   TIM KIEM KHACH HANG
        */
        function ajax_search_customer(context,totalrow,limit,count){
            if(context == "default"){
                page = '1';
            }
            var iTotalrow = parseInt(totalrow);
            var iLimit = parseInt(limit);
            if(context == "next"){
                page = parseInt($("#pageIndex").html());
                if(((page+1)*iLimit)<(iTotalrow+iLimit)){
                    page = page + 1;
                }else{
                    return;
                }
            }
            if(context == "previous"){
                page = parseInt($("#pageIndex").html());
                if(page>1){
                    page = page - 1;
                }else{
                    return;
                }
            }
            if(context == "update"){
                page = parseInt($("#pageIndex").html());
                var iCount = parseInt(count);
                if((page*iLimit) >= (iTotalrow+iLimit-iCount)){
                    page --;
                }
            }
            
            if(context == "jump")
            {
                page = count;
            }
            
            if(context != "default" && context != "previous" && 
                context != "update" && context != "next" && context != "jump"){
                var data = {
                    task: 'search_customer',
                    key_search: context,
                    page: page
                }
            }else{
                var data = {
                    task: 'search_customer',
                    key_search: $("#key_search").val(),
                    page: page
                }
            }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }

        /*
        *   THE HIEN DANH SACH NHAN XET CUA 1 KHACH HANG
        *   CO PHAN TRANG
        */        
//        function ajax_view_all_comments_of_customer(context,totalrow,limit,count){
//                if(context == "default"){
//                    page = '1';
//                }
//                var iTotalrow = parseInt(totalrow);
//                var iLimit = parseInt(limit);
//                if(context == "next"){
//                    page = parseInt($("#pageIndex").html());
//                    if(((page+1)*iLimit)<(iTotalrow+iLimit)){
//                        page = page + 1;
//                    }else{
//                        return;
//                    }
//                }
//                if(context == "previous"){
//                    page = parseInt($("#pageIndex").html());
//                    if(page>1){
//                        page = page - 1;
//                    }else{
//                        return;
//                    }
//                }
//                if(context == "update"){
//                    page = parseInt($("#pageIndex").html());
//                    var iCount = parseInt(count);
//                    if((page*iLimit) >= (iTotalrow+iLimit-iCount)){
//                        page --;
//                    }
//                }
//                
//                if(context == "jump"){
//                    page = count;
//                }                
//                        
//            if($("#key_search").val() == ""){
//                var data = {
//                    task: 'view_all_comments_of_customer',
//                    id: id,
//                    page: page
//                }
//            }else{
//                var data = {
//                    task: 'view_all_comments_of_customer',
//                    id: id,
//                    key_search: $("#key_search").val(),
//                    page: page
//                }
//            }
//            
//            $.get("controller.aspx",data, function(res){
//                $('#contentManagement').html(res);
//            }, "text");            
//        }

        
//       /************************************************************************************************
//                           NHAN XET 
//        ************************************************************************************************

        /*
        *   THE HIEN DANH SACH NHAN XET
        *   CO PHAN TRANG
        */        
        function ajax_manage_comment(context,totalrow,limit,count){
            if(context == "default"){
                page = '1';
            }
            var iTotalrow = parseInt(totalrow);
            var iLimit = parseInt(limit);
            if(context == "next"){
                page = parseInt($("#pageIndex").html());
                if(((page+1)*iLimit)<(iTotalrow+iLimit)){
                    page = page + 1;
                }else{
                    return;
                }
            }
            if(context == "previous"){
                page = parseInt($("#pageIndex").html());
                if(page>1){
                    page = page - 1;
                }else{
                    return;
                }
            }
            if(context == "update"){
                page = parseInt($("#pageIndex").html());
                var iCount = parseInt(count);
                if((page*iLimit) >= (iTotalrow+iLimit-iCount)){
                    page --;
                }
            }
            
            if(context == "jump"){
                page = count;
            }
                
            var data = {
                task: 'manage_comment',
                page: page
            }
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");        
        }
        
        /*
        *   XOA 1 NHAN XET
        */
        function ajax_delete_comment(id,totalrow,limit,search){
            var choose = confirm('Bạn có muốn xóa nhận xét này?');
            if(choose == true){
                var data = {
                    task: 'delete_comment',
                    id: id
                }
                $.get("controller.aspx",data, function(){
                    alert("Xóa thành công");
                    if(search == 'false'){
                        ajax_manage_comment("update",totalrow,limit,1);
                    }else{
                    }
                }, "text");
            }        
        }        
        
        /*
        *   XOA NHIEU NHAN XET KHI DUOC CHON
        */
        function ajax_delete_checked_comment(totalrow,limit,search){
            var checkedIDList = document.getElementsByName("checkedIDList[]");
            var strCheckedIDList = "";
            var flag = false;
            var count = 0;
            for (i = 0; i < checkedIDList.length; i++){
                if(flag == false){
                    if(checkedIDList[i].checked == true){
                        strCheckedIDList = strCheckedIDList + checkedIDList[i].value;
                        flag = true;
                        count ++;
                    }
                }else{
                    if(checkedIDList[i].checked == true){
                        strCheckedIDList = strCheckedIDList + "," + checkedIDList[i].value;
                        count ++;
                    }
                }
            }

            if(strCheckedIDList == ""){
                return;
            }
            var choose = confirm('Bạn có muốn xóa các nhận xét đã chọn?');
            if(choose == true){
                var data = {
                    task: 'delete_checked_comment',
                    checkedIDList: strCheckedIDList
                }
                $.get("controller.aspx",data, function(){
                    alert("Xóa thành công");
                    if(search == 'false'){
                        ajax_manage_comment("update",totalrow,limit,count);
                    }else{
                    }
                }, "text");
            }        
        }
        
        /*
        *   THE HIEN CHI TIET 1 NHAN XET
        */
        function ajax_view_detail_comment(id){
                var data = {
                    task: 'view_detail_comment',
                    id: id
                }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }        
        
        /*
        *   DUYET 1 NHAN XET
        */
        function ajax_accept_comment(id,totalrow,limit){
                var data = {
                    task: 'accept_comment',
                    id: id
                }
            
            $.get("controller.aspx",data, function(){
                alert("Duyệt thành công.");
                ajax_manage_comment("default",totalrow,limit,1);
            }, "text");
        }       
        
//       /************************************************************************************************
//                           HOA DON 
//        ************************************************************************************************         

        /*
        *   QUAN LY HOA DON
        */
        function ajax_manage_bill(context,totalrow,limit,count){
            if(context == "default"){
                page = '1';
            }
            var iTotalrow = parseInt(totalrow);
            var iLimit = parseInt(limit);
            if(context == "next"){
                page = parseInt($("#pageIndex").html());
                if(((page+1)*iLimit)<(iTotalrow+iLimit)){
                    page = page + 1;
                }else{
                    return;
                }
            }
            if(context == "previous"){
                page = parseInt($("#pageIndex").html());
                if(page>1){
                    page = page - 1;
                }else{
                    return;
                }
            }
            if(context == "update"){
                page = parseInt($("#pageIndex").html());
                var iCount = parseInt(count);
                if((page*iLimit) >= (iTotalrow+iLimit-iCount)){
                    page --;
                }
            }
            
            if(context == "jump"){
                page = count;
            }
                
            var data = {
                task: 'manage_bill',
                page: page
            }
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");        
        }        

        /*
        *   CHI TIET HOA DON
        */
        function ajax_view_detail_bill(id){
//            if($("#key_search").val() == ""){
                var data = {
                    task: 'view_detail_bill',
                    id: id
                }
//            }else{
//                var data = {
//                    task: 'view_detail_bill',
//                    id: id,
//                    key_search: $("#key_search").val()
//                }
//            }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }

        /*
        *   DUYET HOA DON
        */
        function ajax_accept_bill(id,totalrow,limit){
                var data = {
                    task: 'accept_bill',
                    id: id
                }
            
            $.get("controller.aspx",data, function(){
                alert("Duyệt thành công.");
                ajax_manage_bill("default",totalrow,limit,1);
            }, "text");
        }       

        /*
        *   TIM KIEM HOA DON
        */
        function ajax_search_bill(context,totalrow,limit,count,key_search){
            if(context == "default"){
                page = '1';
            }
            var iTotalrow = parseInt(totalrow);
            var iLimit = parseInt(limit);
            if(context == "next"){
                page = parseInt($("#pageIndex").html());
                if(((page+1)*iLimit)<(iTotalrow+iLimit)){
                    page = page + 1;
                }else{
                    return;
                }
            }
            if(context == "previous"){
                page = parseInt($("#pageIndex").html());
                if(page>1){
                    page = page - 1;
                }else{
                    return;
                }
            }
            if(context == "update"){
                page = parseInt($("#pageIndex").html());
                var iCount = parseInt(count);
                if((page*iLimit) >= (iTotalrow+iLimit-iCount)){
                    page --;
                }
            }
            
            if(context == "jump")
            {
                page = count;
            }
            
            if(key_search == '-1'){
                key_search = $("#value_search_year_from").val();
                if($("#value_search_month_from").val() != null){
                    key_search = key_search + "," + $("#value_search_month_from").val();
                }
                if($("#value_search_day_from").val() != null){
                    key_search = key_search + "," + $("#value_search_day_from").val();
                }
                
                key_search = key_search + "," + $("#value_search_year_to").val();
                if($("#value_search_month_to").val() != null){
                    key_search = key_search + "," + $("#value_search_month_to").val();
                }
                if($("#value_search_day_to").val() != null){
                    key_search = key_search + "," + $("#value_search_day_to").val();
                }                
            }
            
                var data = {
                    task: 'search_bill',
                    key_search: key_search,
                    page: page
                }
            
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");
        }

//       /************************************************************************************************
//                           LAP DOANH THU 
//        ************************************************************************************************         

        /*
        *   THAY DOI FORM CHON LOAI BAO CAO
        */
        function change_type_income(value){
            var res = '';
            if(value == 'choose_income_year'){
                $("#span_income_quarter_or_month").html(res);
            }
            
            if(value == 'choose_income_quarter'){
                res = "quý <select id='value_income_quarter'>";
                for(i=1; i<=4; i++){
                    res = res + "<option value='"+i+"'>"+i+"</option>";
                }
                res = res + "</select>&nbsp;&nbsp;";
                
                $("#span_income_quarter_or_month").html(res);
            }
            
            if(value == 'choose_income_month'){
                res = "tháng <select id='value_income_month'>";
                for(i=1; i<=12; i++){
                    res = res + "<option value='"+i+"'>"+i+"</option>";
                }
                res = res + "</select>&nbsp;&nbsp;";
                                
                $("#span_income_quarter_or_month").html(res);            
            }                        
        }
        
        /*
        *   THE HIEN FORM CHON LOAI BAO CAO
        */
        function ajax_manage_income_default(){
                var data = {
                    task: 'manage_income_default'
                }
                
            $.get("controller.aspx",data, function(res){
                $('#contentManagement').html(res);
            }, "text");            
        }

        /*
        *   THE HIEN BAO CAO DOANH THU
        */        
        function ajax_manage_income_show(context,totalrow,limit,count){
            // tinh toan so trang
            if(context == "default"){
                page = '1';
            }
            var iTotalrow = parseInt(totalrow);
            var iLimit = parseInt(limit);
            if(context == "next"){
                page = parseInt($("#pageIndex").html());
                if(((page+1)*iLimit)<(iTotalrow+iLimit)){
                    page = page + 1;
                }else{
                    return;
                }
            }
            if(context == "previous"){
                page = parseInt($("#pageIndex").html());
                if(page>1){
                    page = page - 1;
                }else{
                    return;
                }
            }
            if(context == "jump")
            {
                page = count;
            }
                        
            // lay doanh thu duoc chon
            var choose_income = $('#choose_income').val();
            
            var data = {};
            if(choose_income == 'choose_income_year'){
                data = {
                    task: 'manage_income_show',
                    choose_income: 'choose_income_year',
                    value_income_year: $('#value_income_year').val(),
                    page: page
                };                
            }
            
            if(choose_income == 'choose_income_quarter'){
                data = {
                    task: 'manage_income_show',
                    choose_income: 'choose_income_quarter',
                    value_income_year: $('#value_income_year').val(),
                    value_income_quarter: $('#value_income_quarter').val(),
                    page: page
                };                                
            }
            
            if(choose_income == 'choose_income_month'){
                data = {
                    task: 'manage_income_show',
                    choose_income: 'choose_income_month',
                    value_income_year: $('#value_income_year').val(),
                    value_income_month: $('#value_income_month').val(),
                    page: page
                };                                
            }
            
            $.get("controller.aspx",data, function(res){
                $('#show_income_region').html(res);
            }, "text");                        
        }                
                